package com.kele.reposity.impl;

import com.kele.entity.User;
import com.kele.reposity.UserReposity;
import org.springframework.stereotype.Repository;

import java.util.*;

/**
 * @Version 2019
 * @Author:kele
 * @Date:2021/8/7
 * @Content:
 * @Description：
 */
@Repository
public class UserRepository implements UserReposity {

    public static Map<Integer , User> map;
    static {
        map=new HashMap<>();
        map.put(1,new User(1,"kele1"));
        map.put(2,new User(2,"kele2"));
        map.put(3,new User(3,"kele3"));
    }
    @Override
    public Collection<User> findAll() {

        return map.values();
    }

    @Override
    public void addOrUpdate(User user) {
        map.put(user.getId(),user);
    }

    @Override
    public User findById(Integer id) {
        return map.get(id);
    }

    @Override
    public void deleteById(Integer id) {
        map.remove(id);
    }
}
